<template>
  <div>
    <div class="top">
			<div class="pic"> 
				<img src="../assets/login/defualt_user_head.png">
			</div>
		</div>
		<div class="tab">
			<div class="activ">
				登录
			</div>
			<div @click="registered()">
				注册
			</div>
		</div>
		 <div class="list">
			<div class="boxt">
				<div class="infos">
					<span>
						<img src="../assets/login/wode.png" alt="">
						<span>用户名</span>
					</span>
					<input type="text" v-model="phone" placeholder="请输入手机号码">
				</div>
			</div>
			<div class="boxt" v-if="!hid">
				<div class="infos">
					<span>
						<img src="../assets/login/yaoshi.png" alt="">
						<span>用户密码</span>
					</span>
					<input type="password" v-model="password" placeholder="请输入登录密码">
				</div>
			</div> 
			<div class="boxt" v-if="hid">
				<div class="infos">
					<b>
						<img src="../assets/login/duanxing.png" alt="">
					</b>
					<input type="text" v-model="num" placeholder="请输入短信验证码">
					<yd-sendcode slot="right" 
												v-model="start1" 
												@click.native="sendCode1" 
												type="danger"
					></yd-sendcode>
				</div>
			</div> 
			<div class="mimax"  v-if="!hid">
				<div></div>
				<div @click="zhaohui()">忘记密码？</div> 
			</div>
			<!-- 账号密码登陆 -->
			<div class="denglu" @click="mima()" v-if="!hid">登录</div>

			<!-- 手机验证码登陆 -->
			<div class="denglu ddd" @click="yzm()" v-if="hid">登录</div>

			<div class="mimax" v-if="!hid">
				<div @click="qiehuan()">短信验证码登录</div>
				<div></div> 
			</div>
			<div class="mimax" v-if="hid">
				<div @click="qiehuan()">账户密码登录</div>
				<div></div> 
			</div>
		</div>
  </div>
</template>

<script>
export default {
  name: "inform",
  data() {
    return {
      start1: false,
      hid: false,
      password: "",
      phone: "",
      num: ""
    };
  },
  methods: {
    //注册跳转
    registered: function() {
      this.$router.push("/registered");
    },
    //找回密码
    zhaohui: function() {
      this.$router.push("/zaohui");
    },
    qiehuan() {
      this.hid = !this.hid;
    },
    //密码登录
    mima: function() {
      let self = this;
      let url = "/api/login/enter";
      self.httpPost(
        url,
        { phone: this.phone, password: this.password },
        function(res) {
          if (res.code == 200) {
            localStorage.setItem("mytoken", res.data.login_token);
            localStorage.setItem("leve", res.data.level);
            localStorage.setItem("myid", res.data.id);
            setTimeout(() => {
              self.$router.push("/");
            }, 1000);
          } else {
            self.$dialog.loading.close();
            self.$dialog.toast({
              mes: res.msg,
              icon: "error",
              timeout: 1500
            });
          }
        }
      );
    },
    //验证码登陆
    yzm: function() {
      let self = this;
      let url = "/api/login/code";
      self.httpPost(
        url,
        { phone: this.phone, code: this.num, type: 2 },
        function(res) {
          if (res.code == 200) {
            localStorage.setItem("mytoken", res.data.login_token);
            localStorage.setItem("myid", res.data.id);
            setTimeout(() => {
              self.$router.push("/");
            }, 1000);
          } else {
            self.$dialog.loading.close();
            self.$dialog.toast({
              mes: res.msg,
              icon: "error",
              timeout: 1500
            });
          }
        }
      );
    },

    //验证码获取
    sendCode1() {
      let self = this;
      let reg_str = /^1\d{10}$/;
      if (!reg_str.test(this.phone)) {
        this.$dialog.notify({
          mes: "请输入正确手机号码！",
          timeout: 3000
        });
        return;
      }
      this.$dialog.loading.open("发送中...");
      let url = "/api/login/send";
      self.httpPost(url, { phone: this.phone, type: 2 }, function(res) {
        if (res.code == 200) {
          setTimeout(() => {
            self.start1 = true;
            self.$dialog.loading.close();
            self.$dialog.toast({
              mes: res.msg,
              icon: "success",
              timeout: 1500
            });
          }, 1000);
        } else {
          self.$dialog.loading.close();
          self.$dialog.toast({
            mes: res.msg,
            icon: "error",
            timeout: 1500
          });
        }
      });
    }
  }
};
</script>


<style scoped>
.top {
  width: 100%;
  height: 3.22rem;
  background: #b63554;
  display: flex;
  justify-content: center;
  align-items: center;
}
.top .pic {
  width: 1.28rem;
  height: 1.28rem;
  border-radius: 50%;
}
.top .pic img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}
.tab {
  width: 100%;
  height: 1rem;
  background: #ff485c;
  display: flex;
}
.tab > div {
  width: 50%;
  text-align: center;
  color: #fff;
  font-size: 0.32rem;
  line-height: 1rem;
}
.activ {
  position: relative;
}
.activ::after {
  display: block;
  content: "";
  clear: both;
  position: absolute;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 7px solid transparent;
  border-bottom: 7px solid #fff;
  bottom: 0;
  left: 50%;
  margin-left: -7.2px;
}
.list {
  width: 100%;
  padding: 0 0.3rem;
  background: #fff;
}
.list .boxt {
  width: 100%;
  height: 1rem;
  background: #fff;
  display: flex;
  align-items: center;
}
.list .boxt .info {
  width: 100%;
  height: 100%;
  line-height: 1.4rem;
  border-bottom: 1px solid #eee;
}

.list .boxt .info span {
  font-size: 0.28rem;
  color: #707070;
  /* width: 1.2rem; */
  display: inline-block;
}
.boxt span {
  font-size: 0.28rem;
  color: #333;
}
.info > span {
  display: flex;
  align-items: center;
}

.infos {
  padding-top: 0.15rem;
  border-bottom: 1px solid #eee;
  width: 100%;
  display: flex;
  height: 1rem;
  align-items: center;
}
.infos input {
  height: 0.7rem;
  flex: 1;
  border: none;
  color: #333;
  font-family: "微软雅黑";
  font-size: 0.3rem;
}
.infos span {
  display: flex;
  align-items: center;
  color: #333;
  width: 1.9rem;
  font-size: 0.31rem;
}
.infos img {
  width: 0.36rem;
  margin-right: 0.15rem;
  position: relative;
}
input::-webkit-input-placeholder,
textarea::-webkit-input-placeholder {
  color: #9e9e9e;
}
input:-moz-placeholder,
textarea:-moz-placeholder {
  color: #9e9e9e;
}
input::-moz-placeholder,
textarea::-moz-placeholder {
  color: #9e9e9e;
}
input:-ms-input-placeholder,
textarea:-ms-input-placeholder {
  color: #9e9e9e;
}
.mimax {
  font-size: 0.25rem;
  height: 1rem;
  align-items: center;
  color: #666;
  display: flex;
  justify-content: space-between;
}
.denglu {
  height: 0.8rem;
  border-radius: 25px;
  text-align: center;
  background: #ff485c;
  font-size: 0.35rem;
  color: #fff;
  line-height: 0.8rem;
}
.ddd {
  margin-top: 1rem;
}
</style>
